   
    
    var account=$api.getStorage('account');
    var commuser=$api.getStorage('member2');
    
    var city = commuser.address;	//城市
    var compounds=commuser.compounds;  //小区
    var unitName=commuser.unitName;  //单元
    var roomNumber=commuser.roomNumber;  //房号
    
    var memberID=commuser.memberID;  //用户id
    var status=commuser.status;  //状态
    var zycode=commuser.zycode;  //资源编码
    
	apiready = function(){
	
		//监听城市改变事件
		api.addEventListener({
		    name: 'selectCity'
		}, function(ret){
		    if(ret){
		        changeCity(ret.value);
		    }
		});
	
	    //监听小区改变事件
		api.addEventListener({
		    name: 'selectCompound'
		}, function(ret){
		    if(ret){
		        changeCompound(ret.value);
		    }
		});
		
		 //监听单元改变事件
		api.addEventListener({
		    name: 'selectUnit'
		}, function(ret){
		    if(ret){
		         changeUnit(ret.value);
		    }
		});
		
		 //监听房号改变事件
		api.addEventListener({
		    name: 'selectRoom'
		}, function(ret){
		    if(ret){
		         changeRoom(ret.value);
		    }
		});
	
		 init();
		 
		 
	};
	
	
    //初始化用户信息
	function init(){
	     $api.text($api.byId('account'), commuser.account);
	     $api.val($api.byId('realName'), commuser.realName);
	     $api.val($api.byId('nickName'), commuser.nickName);
	     $api.val($api.byId('mobile'), commuser.mobile);
	     $api.val($api.byId('ownerName'), commuser.ownerName);
	     
	     $api.val($api.byId('city'), commuser.address);
	     $api.val($api.byId('compounds'), commuser.compounds);
	     $api.val($api.byId('unitName'), commuser.unitName);
	     $api.val($api.byId('roomNumber'), commuser.roomNumber);
	     
	     $api.text($api.byId('city_text'), commuser.address);
	     $api.text($api.byId('compounds_text'), commuser.compounds);
	     $api.text($api.byId('unitName_text'), commuser.unitName);
	     $api.text($api.byId('roomNumber_text'), commuser.roomNumber);
	     
	};
	
	//改变城市
	function changeCity(c){
	      $api.text($api.byId('city_text'), c);
	      
	      $api.text($api.byId('compounds_text'), '');
	      $api.text($api.byId('unitName_text'), '');
	      $api.text($api.byId('roomNumber_text'), '');
	      
	      $api.val($api.byId('city'),c);
	      
	      $api.val($api.byId('compounds'),'');
	      $api.val($api.byId('unitName'), '');
	      $api.val($api.byId('roomNumber'), '');
	      
	      city = c;
	      compounds='';
	      unitName='';
	      roomNumber='';
	};
	
	//改变小区
	function changeCompound(compound){
	      $api.text($api.byId('compounds_text'), compound);
	      
	      $api.text($api.byId('unitName_text'), '');
	      
	      $api.text($api.byId('roomNumber_text'), '');
	      
	      $api.val($api.byId('compounds'),compound);
	      $api.val($api.byId('unitName'), '');
	      $api.val($api.byId('roomNumber'), '');
	      
	      compounds=compound;
	      unitName='';
	      roomNumber='';
	      
	      checkowner2();
	};
	
	//改变单元
	function changeUnit(unit){
	   
	    $api.text($api.byId('unitName_text'), unit);
	    
	    $api.text($api.byId('roomNumber_text'), '');
	    
	    
	     $api.val($api.byId('unitName'), unit);
	     $api.val($api.byId('roomNumber'), '');
	     
	     unitName=unit;
	     
	     checkowner2();
	};
	
	
	//改变房号
	function changeRoom(room){
	     
	     $api.text($api.byId('roomNumber_text'), room);
	     
	     $api.val($api.byId('roomNumber'), room);
	     
	     roomNumber=room;
	     checkowner2();
	};
	
	//选择城市
	function opencity(){
	     
	     openWin('selcity');
	}
	
	//选择城市
	function openpound(){
	     if(city==''){
	           toast('请选择城市!');
	           return;
	     }
	     
	     openWin('selcommunitys', {'city':city});
	}
	
	//选择单元
	function openunit(){
	     if(compounds==''){
	           toast('请选择小区!');
	           return;
	     }
	     
	     openWin('selunit',{'compounds':compounds});
	}
	
	//选择房号
	function openroom(){
	     if(unitName==''){
	           toast('请选择单元!');
	           return;
	     }
	     
	     openWin('selroom',{'unit':unitName});
	}
	
	//验证业主
	function checkowner(){
	    
	    var ownerName=$api.byId('ownerName').value;
	   
	    if(ownerName==''){
	            toast('请输入业主姓名!');
	            return;
	    }
	      
	      var param='?ownerName='+ownerName+'&compounds='+compounds+'&unitName='+unitName+'&roomNumber='+roomNumber;
	      do_ajax('/app/checkowner'+param,'get',{},function(ret,err){
	            api.hideProgress();
	            if(ret){
	                 
	                 if(ret.resultCode=='0'){
	                        
	                        status='已认证';
	                        zycode=ret.code;  //GZ01-01-01-2910
	                        api.alert({msg: '验证通过'});
	                 
	                 }else{
	                        
	                        status='未认证';
	                        zycode='';
	                        api.alert({msg: '验证不通过，请填写正确信息或拨打电话'});
	                 
	                 }
	                 
	            
	            }else{
	            
	                    api.alert({
				            msg:('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode)
				        });
				        api.hideProgress();
	            }
	       
	       });
	}
	
	
	//验证业主
	function checkowner2(){
	    
	      var ownerName=$api.byId('ownerName').value;
	
	      var param='?ownerName='+ownerName+'&compounds='+compounds+'&unitName='+unitName+'&roomNumber='+roomNumber;
	      
	      do_ajax('/app/checkowner'+param,'get',{},function(ret,err){
                      api.hideProgress();
                     if(ret.resultCode=='0'){
                            status='已认证';
                            zycode=ret.code;
                     
                     }else{
                            status='未认证';
                            zycode='';
                     }
           });
	}
	
	
	//保存修改
	function saveupdate(){
	       
	       var realName=$api.byId('realName').value;
	       
	       if(realName==''){
	             toast('输入真实姓名!');
	             return;
	       }
	       
	       var data={
	             'memberID':memberID,
	             'realName':realName,
	             'nickName':$api.byId('nickName').value,
	             'mobile':$api.byId('mobile').value,
	             'compounds':compounds,
	             'unitName':unitName,
	             'roomNumber':roomNumber,
	             'status':status,
	             'zycode':zycode,
	             'ownerName':$api.byId('ownerName').value,
	       		 'address':city,
	       };
	       
	       
	       do_ajax("/app/commuser/update",'post',data,function(result,err){
				api.hideProgress();
				if(result.resultCode == '0') {
				    
				    $api.setStorage('member2',result.member2);
				    //发送刷新用户信息事件
				    api.sendEvent({
					    name: 'refreshuser',
					});
					
					api.sendEvent({
					    name: 'refreshUserinfo',
					});
					
				    toast('修改成功!');
				    setTimeout(function () {
		 			    api.closeWin();
		            }, 1000);
		            
		 		}else{
		 			 toast(result.datas);
		 		}
		 	});
	};
	

